import ServiceBase from '../base';
import {httpResultProxy} from '../proxy';

class AppService extends ServiceBase {
    getAllApp(data) {
        let promise = super.get({
            url: `/apps/search`,
            params: data.data,
        });
        return httpResultProxy(promise);
    }

    getAllAccountApp(data) {
        let promise = super.get({
            url: `/accounts/${data.accountId}/apps`,
            params: data.data,
        });
        return httpResultProxy(promise);
    }

    installAppToAccount(data) {
        let promise = super.post({
            url: `/accounts/${data.accountId}/apps/${data.appId}`,
            data: data.data,
        });
        return httpResultProxy(promise);
    }

    unloadingAccountApp(data) {
        let promise = super.delete({
            url: `/accounts/${data.accountId}/apps/${data.appId}`,
        });
        return httpResultProxy(promise);
    }

    createApp(data) {
        let promise = super.post({
            url: `/apps/${data.appId}`,
            data: data.data,
        });
        return httpResultProxy(promise);
    }

    getAppByAppId(data) {
        let promise = super.get({
            url: `/apps/${data.appId}`,
        });
        return httpResultProxy(promise);
    }

    updateAppState(data) {
        let promise = super.put({
            url: `/apps/${data.appId}/state`,
            data: data.data,
        });
        return httpResultProxy(promise);
    }

    deleteApp(data) {
        let promise = super.delete({
            url: `/apps/${data.appId}`,
        });
        return httpResultProxy(promise);
    }
}

export default AppService;
